package action.admin;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Enumeration;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import service.mail.ClientGestionEmail;
import service.outils.StringHelper;
import service.securite.DroitsAcces;
import service.securite.GenerationMotDePasse;
import service.securite.Md5;
import service.validateur.ValidateurClient;
import bdd.BddClientSelectRequest;
import bdd.BddClientUpdateRequest;
import bdd.BddNews;
import bdd.ServiceBdd;
import bean.client.Client;
import bean.produit.Service;

public class AdminGestionNewsAction extends Action {

	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminGestionNewsAction() {
        super();
    }

    public static boolean aLesDroits(HttpServletRequest request) {
    	return (DroitsAcces.isAdmin(request));
    }
    
	protected void initSession(HttpServletRequest request )
	{
		HttpSession session = request.getSession();
	}
	
	/**
	 */
	public ActionForward execute(final ActionMapping pMapping,
			ActionForm pForm, final HttpServletRequest request,
			HttpServletResponse response) {
		
		this.initSession(request);
		
		try {
			
			int id_service = (Integer) request.getSession().getAttribute("id_service");
			
			ArrayList<Service> listeService = ServiceBdd.getService(id_service);
			request.setAttribute("listeService", listeService);
			if(request.getParameter("texte") != null)
				BddNews.miseAJourNews(Integer.parseInt(request.getParameter("service")), request.getParameter("texte"));
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
//		if (!aLesDroits(request)) {
//			return pMapping.findForward("error");
//		}
		return pMapping.findForward("success");		
	}
}
